package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.AppCodeBean;
import com.system.healthproject.bean.AppCodeResultBean;
import com.system.healthproject.bean.AppCodeUserBean;
import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.paramsbean.AppCodeParams;
import com.system.healthproject.model.admin.service.AppCodeService;
import com.system.healthproject.pojo.AppCode;
import com.system.healthproject.pojo.Doctor;
import com.system.healthproject.pojo.Hospital;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.print.Doc;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.*;

/**
 * @author Xuheng Zhou
 * @date 2020/6/9 9:38
 * @desc
 */
@Controller
@Api(value = "后端-二维码管理模块",tags = "后端-二维码管理API")
@RequestMapping("/admin/AppCode")
@Validated
public class AppCodeController {

    @Autowired
    AppCodeService appCodeService;


    @ApiOperation(value = "多条件查询二维码信息接口(后台已调)",notes = "多条件查询二维码信息",httpMethod = "post")
    @RequestMapping(value = "/selectAppCodeWhere",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectName",value = "项目名称",dataType = "String"),
            @ApiImplicitParam(name = "hospitalName",value = "发放医院",dataType = "String"),
            @ApiImplicitParam(name = "appcodeCreatetime",value = "创建时间",dataType = "Date"),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "Integer")
    })
    public ApiResult<PagesBean<AppCodeResultBean>> selectAppCodeWhere
            ( @NotBlank String projectName,
              @NotBlank String hospitalName,
              @NotBlank String appcodeCreatetime,
              @NotNull  Integer page,
              @NotNull  Integer size
    ){
        PagesBean<AppCodeResultBean> pagesBean=
                appCodeService.selectAppCodeWhere(page,size,projectName,hospitalName,appcodeCreatetime);

        return ApiResult.successWithData("查询成功",pagesBean);
    }

    @ApiOperation(value = "查询二维码详情信息接口(后台已调)",notes = "查询某个二维码详情信息",httpMethod = "post")
    @RequestMapping(value = "/selectOneAppCode",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "appcodeId",value = "二维码id",dataType = "String",required = true)
    public ApiResult<AppCodeBean> selectOneAppCode(
            @RequestParam @NotNull Integer appcodeId){

        AppCodeBean appCodeBean=appCodeService.selectOneAppCode(appcodeId);

        return ApiResult.successWithData("查询成功",appCodeBean);
    }

    @ApiOperation(value = "二维码信息新增接口(后台已调)",notes = "新增二维码信息",httpMethod = "post")
    @RequestMapping(value = "/insertAppCode",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult insertAppCode(@Validated @RequestBody AppCodeParams appCode) {
        boolean b = appCodeService.insertAppCode(appCode);
        return ApiResult.withBoolean(b);
    }

    @ApiOperation(value = "二维码删除",notes = "二维码删除",httpMethod = "post")
    @RequestMapping(value = "/deleteAppCode"
            ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult deleteAppCode(@NotNull Integer appCodeId) {
        boolean b = appCodeService.deleteAppCode(appCodeId);
        return ApiResult.withBoolean(b);
    }


    /**
     * 查询二维码使用用户信息
     * @param appcodeId
     * @return
     */
    @ApiOperation(value = "查询二维码使用用户信息接口(后台已调)",notes = "查询二维码使用用户信息",httpMethod = "post")
    @RequestMapping(value = "/selectUsePatientbyCode",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appcodeId",value = "二维码id",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "String",required = true),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "String",required = true)
})
    public ApiResult<PagesBean<AppCodeUserBean>> selectUsePatientbyCode(
            @NotNull Integer appcodeId,
            @NotNull Integer page,
            @NotNull Integer size){

        PagesBean<AppCodeUserBean> pagesBean=
                appCodeService.selectUsePatientbyCode(appcodeId,page,size);
        return ApiResult.successWithData("查询信息成功",pagesBean);
    }




}
